﻿#define _CRT_SECURE_NO_WARNINGS
#include"smart_pointer.h"
#include"Date.h"
using std::move;
int main()
{
	smart_pointer::auto_ptr<Date> ap1(new Date);
	// 拷⻉时，管理权限转移，被拷⻉对象ap1悬空
	smart_pointer::auto_ptr<Date> ap2(ap1);
	// 空指针访问，ap1对象已经悬空
	//ap1->_year++;
	smart_pointer::unique_ptr<Date> up1(new Date);
	// 不⽀持拷⻉
	//unique_ptr<Date> up2(up1);
	// ⽀持移动，但是移动后up1也悬空，所以使⽤移动要谨慎
	smart_pointer::unique_ptr<Date> up3(move(up1));
	smart_pointer::shared_ptr<Date> sp1(new Date);
	// ⽀持拷⻉
	smart_pointer::shared_ptr<Date> sp2(sp1);
	smart_pointer::shared_ptr<Date> sp3(sp2);
	cout << sp1.use_count() << endl;
	sp1->_year++;
	cout << sp1->_year << endl;
	cout << sp2->_year << endl;
	cout << sp3->_year << endl;
	//定制删除器
	smart_pointer::shared_ptr<Date> sp4(new Date[10], [](Date* p) { delete[] p; });
	return 0;
}